package admin;

import test.LocalProperties;

import com.objective.oji.OjiApplication;
import com.objective.oji.OjiException;
import com.objective.oji.OjiSession;

public class LocalObjSession {
    public OjiApplication objective = new OjiApplication();
    protected OjiSession apiSession;

    public LocalObjSession(LocalProperties AppProfile, SERVER_TYPE Selected_SERVER_PROFILE, LOGINMETHOD Login_Method_TYPE) {

	LoginDetails myLoginDetails = new LoginDetails(AppProfile, Selected_SERVER_PROFILE, Login_Method_TYPE);
	connection(myLoginDetails.getUserName(), myLoginDetails.getPassword(), myLoginDetails.getServerName(),
		myLoginDetails.getPort());
    }

    public void connection(String user_name, String password, String server_name, int port) {

	try {
	    apiSession = objective.loginUser(user_name, password, server_name, port);
	    System.out.println("Server       : " + server_name + " (" + port + ")");
	    System.out.println("Connected As : " + apiSession.getCurrentUser().getName());
	} catch (OjiException e) {
	    e.printStackTrace();
	    System.out.print("\n \n  LOGIN Failed ");
	    System.exit(1);
	}
    }

    public void disconnection() {
	apiSession.logout();
	System.out.println("Disconnected: " + apiSession.getCurrentUser().getName());
    }
}

